// -------------------------------------------------------------
// api: project.app.create
// time: 2020-07-30
// author: minner
// -------------------------------------------------------------
exports['project.app.create'] = obj_api = {
    '1.0': function (args, session, callback) {
        if (!session.account_id) {
            return callback(12, null, '会话已失效');
        }

        if (!args.project_id || typeof args.project_id != 'number') {
            return callback(11, null, '缺少参数(project_id)');
        }
        if (!args.project_app_name || typeof args.project_app_name != 'string') {
            return callback(11, null, '缺少参数(project_app_name)');
        }
        if (!args.description || typeof args.description != 'string') {
            return callback(11, null, '缺少参数(description)');
        }

        let sql_insert = "INSERT INTO `deploy_project_app`" +
            " (`project_app_name`, `create_time`, `creator`, `status`, `description`, `project_id`)" +
            " VALUES (" +
            mysql.escape(args.project_app_name) + ", '" +
            uim.dateTime() + "', " +
            session.account_id + ", '1', " +
            mysql.escape(args.description) + ", " +
            args.project_id + ")";

        uim.db_query(sql_insert, function (err, results, fields) {
            if (err) {
                return callback(6, null, '数据库查询出错：' + err);
            }
            callback(0, {
                project_app_id: results.insertId,
            });
        });
    },

};
